import store from '@/store'
import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
import userRouter from './routers/userRouter'
import lostRouter from './routers/lostRouter'
import scheduleRouter from './routers/scheduleRouter'
import vaccineRouter from './routers/vaccineRouter'
import jobRouter from './routers/jobRouter'
import grkRouter from './routers/grkRouter'
import applicantRouter from './routers/applicantRouter'
/**
 * 私有路由表
 */
const privateRoutes = [...userRouter, ...lostRouter, ...scheduleRouter, ...vaccineRouter, ...jobRouter, ...grkRouter]
/**
 * 公开路由表
 */
const publicRoutes = [
  {
    path: '/',
    redirect: '/profile',
    isParent: true,
    meta: {
      title: '个人信息',
      icon: 'home'
    },
    component: () => import('@/layout/index'),
    children: [
      // 个人中心
      {
        path: '/profile',
        component: () => import('@/views/user/profile/index')
      }
    ]
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/error-page/404')
  },
  // 401
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/error-page/401')
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    meta: {
      title: 'login'
    }
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    meta: {
      title: 'register'
    }
  },
  {
    path: '/index',
    component: () => import('@/views/home/index'),
    meta: {
      title: 'home'
    }
  }
]

const getRouters = () => {
  if (store.getters.userType === 'APPLICANT') {
    return [...publicRoutes, ...applicantRouter]
  } else {
    return [...publicRoutes, ...privateRoutes]
  }
}

const router = createRouter({
  history: createWebHashHistory(),
  // history: createWebHistory(),
  routes: getRouters()
})

export default router
